package nio.buffter;


import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
//堆外内存修改文件
public class mappedBuffterTest1 {
    public static void main(String[] args) throws Exception {
        RandomAccessFile rw = new RandomAccessFile("1.txt", "rw");
        FileChannel channel = rw.getChannel();
        /*
        * 参数1 模式
        * 参数2 起始位置
        * 参数3 映射的内存大小
        */
        MappedByteBuffer mappedByteBuffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, 10);
        mappedByteBuffer.put(0,(byte)'h');
        mappedByteBuffer.put(6,(byte)'W');
        //mappedByteBuffer.put(5,(byte)'1');  内存大小不是索引

        rw.close();
    }
}
